<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 检测昵称是否是有汉字字母数字下划线组成，6-8位 -->
    <script>
        const yourName = prompt('请输入你的昵称');
        // 定义函数
        function name(yourName) {
            if (yourName.length >= 6 && yourName.length <= 8) {
                const reg = /^[\w\u4e00-\u9fa5]{6,8}$/;
                if (reg.test(yourName)) {
                    alert("昵称满足条件");
                } else {
                    alert('昵称不满足汉字字母数字下划线组成的格式要求')
                }
            } else {
                alert('昵称要求范围在6-8位')
            }


        }
        name(yourName)
    </script>
</body>

</html>